package com.stable.utils;

import java.math.BigDecimal;
import java.util.Random;

public class MathUtil {

	public static final int getRandomSecBetween5And15() {
		Random r = new Random();
		int number = r.nextInt(10);
		return (number + 5);
	}
	
	public static final int getRandomSecBetween1And5() {
		Random r = new Random();
		int number = r.nextInt(5);
		return (number+1);
	}
	
	public static final int getRandomSecBetween1And30() {
		Random r = new Random();
		int number = r.nextInt(30);
		return (number + 1);
	}
	
	public static void main(String[] args) {
		System.err.println(getRandomSecBetween1And5());
		System.err.println(getRandomSecBetween1And5());
		System.err.println(getRandomSecBetween1And5());
	}


	/**
	 * 数字转换为万/亿为单位
	 */
	public static String formatNumWanYi(String num) {
		String numN = num.split("\\.")[0];
		if (numN.length() >= 9) {
			BigDecimal divide = new BigDecimal(num).divide(new BigDecimal(100000000)).setScale(2, BigDecimal.ROUND_HALF_UP);
			return divide.toString() + "亿";
		} else {
			BigDecimal divide = new BigDecimal(num).divide(new BigDecimal(10000)).setScale(2, BigDecimal.ROUND_HALF_UP);
			return divide.toString() + "万";
		}
	}

	/**
	 * 数字转换为百分比
	 */
	public static String formatNumBFB(String num) {
		BigDecimal divide = new BigDecimal(num).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		return divide.toString() + "%";
	}
}
